package com.jianguo.web.controller.system;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jianguo.common.annotation.Log;
import com.jianguo.common.core.controller.BaseController;
import com.jianguo.common.core.domain.AjaxResult;
import com.jianguo.common.enums.BusinessType;
import com.jianguo.system.domain.PzDictDistrict;
import com.jianguo.system.service.IPzDictDistrictService;
import com.jianguo.common.utils.poi.ExcelUtil;
import com.jianguo.common.core.page.TableDataInfo;

/**
 * 省市区字典Controller
 *
 * @author xjj
 * @date 2024-03-22
 */
@RestController
@RequestMapping("/system/district")
public class PzDictDistrictController extends BaseController
{
    @Autowired
    private IPzDictDistrictService pzDictDistrictService;

    /**
     * 查询省市区字典列表
     */
    @PreAuthorize("@ss.hasPermi('system:district:list')")
    @GetMapping("/list")
    public TableDataInfo list(PzDictDistrict pzDictDistrict)
    {
        startPage();
        List<PzDictDistrict> list = pzDictDistrictService.selectPzDictDistrictList(pzDictDistrict);
        return getDataTable(list);
    }

    /**
     * 导出省市区字典列表
     */
    @PreAuthorize("@ss.hasPermi('system:district:export')")
    @Log(title = "省市区字典", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PzDictDistrict pzDictDistrict)
    {
        List<PzDictDistrict> list = pzDictDistrictService.selectPzDictDistrictList(pzDictDistrict);
        ExcelUtil<PzDictDistrict> util = new ExcelUtil<PzDictDistrict>(PzDictDistrict.class);
        util.exportExcel(response, list, "省市区字典数据");
    }

    /**
     * 获取省市区字典详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:district:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(pzDictDistrictService.getById(id));
    }

    /**
     * 新增省市区字典
     */
    @PreAuthorize("@ss.hasPermi('system:district:add')")
    @Log(title = "省市区字典", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PzDictDistrict pzDictDistrict) {
        return toAjax(pzDictDistrictService.save(pzDictDistrict));
    }

    /**
     * 修改省市区字典
     */
    @PreAuthorize("@ss.hasPermi('system:district:edit')")
    @Log(title = "省市区字典", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PzDictDistrict pzDictDistrict) {
        return toAjax(pzDictDistrictService.updateById(pzDictDistrict));
    }

    /**
     * 删除省市区字典
     */
    @PreAuthorize("@ss.hasPermi('system:district:remove')")
    @Log(title = "省市区字典", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(pzDictDistrictService.removeByIds(Arrays.asList(ids)));
    }
}
